package org.wj.arithmetic

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object ZipPartitions extends App {

  val conf = new SparkConf().setMaster("local").setAppName(this.getClass.getName)

  val sc = new SparkContext(conf)


  private val r1: RDD[Int] = sc.parallelize(1 to 10, 2)

  private val r2: RDD[Int] = sc.parallelize(20 to 25, 2)

  r1.zipPartitions(r2)((iter1, iter2)=>{
    var result = List[(Int,Int)]()
    while(iter1.hasNext&&iter2.hasNext){
      result ::= (iter1.next(), iter2.next())
    }
    result.iterator
  })


  val s = 10

  val m = s match {
    case i if i> 2 => i*3
    case i if i < 2 => i+3
    case i if i == 2 => i
  }

}
